package 每日一题;

import java.util.Scanner;

public class 连续最大和 {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int size=sc.nextInt();
        int[] arr=new int[size];

        for(int i=0;i<size;i++) {
            arr[i]=sc.nextInt();
        }

        int max=arr[0];
        int sum=arr[0];
        for(int i=1;i<size;i++) {

            if(sum+arr[i]>arr[i]) {
                sum = sum+arr[i];
            }else{
                sum=arr[i];
            }
            if(sum>max) {
                max=sum;
            }
        }
        System.out.println(max);

    }


    public static void main1(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] arr=new int[n];
        for (int i = 0; i <n; i++) {
            arr[i]=sc.nextInt();
        }

        System.out.println(fun(n,arr));
    }

    private static int fun(int n, int[] arr) {
        int[] dp=new int[n];
        dp[0]=arr[0];

        int max=dp[0];

        for (int i = 1; i <arr.length; i++) {
            dp[i]=dp[i-1]>0 ? dp[i-1]+arr[i] :arr[i];
            if (dp[i]>max) {
                max=dp[i];
            }
        }

        return max;
    }
}
